<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<script type="text/javascript" src="${staticPath}/js/decimalinput.js"></script>
<!DOCTYPE script PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<head>
<script type="text/javascript">
$(function(){
	$("#isGuarantee").click(function(){
		if($("#brandName").val() =="0" || $("#brandName").val() == null){
			top.$.jBox.tip('请先选择品牌', 'warning');
			$("#brandName").focus();
		}
	});
	$("#isGuarantee").change(function(){
		if($(this).val()!=null || '' != $(this).val() ){
			var guaranteeAmount;   // 保底金额
			var deductRate;        //扣率
			var guaranteeType;    //保底形式
			var brandId = $("#brandName").val();
			for(var i=0;i<num_base;i++){
				if($("#barndId_base"+i).val() == brandId && $("#isGuarantee_base"+i).val()=="1"){
					guaranteeAmount = $("#guaranteeAmount_base"+i).val();
					deductRate  =  $("#deductRate_base"+i).val();
					guaranteeType =$("#guaranteeType_base"+i).val();
				}
			}
			if($(this).val() ==0){
				$("#guaranteeType").children("option").each(function(){
					if($(this).val() == "" ){
						$(this).attr("selected","selected");
					}
				});
				$("#guaranteeAmount").val("");
				$("#deductRate").val(deductRate);
			}
			if($(this).val() =="1"){
				$("#deductRate").val(deductRate);
				$("#guaranteeAmount").val(guaranteeAmount);
				$("#guaranteeType").children("option").each(function(){
						if($(this).val() == guaranteeType ){
							$(this).attr("selected","selected");
						}
				});
			}
			if($(this).val() ==""){
				$("#deductRate").val("");
				$("#guaranteeAmount").val("");
				$("#guaranteeType").children("option").each(function(){
					if($(this).val() == "" ){
						$(this).attr("selected","selected");
					}
				});
			}
		}
	});
	
	
	//*******************数字校验*********************************
	var operate ='${operate}';
	$("#guaranteeAmount").decimalinput();
	$("#upper").decimalinput();
	$("#lower").decimalinput();
	$("#deductRate").decimalinput();
	//*****************************************************
	var brandIds = '${base.brandsId}';
	var obj = document.getElementById("brandName");

	obj.options.add(new Option("请选择", "0"));
	for(var i=0; i<list.length; i++){
		var brandCname = $("#brandCName"+list[i]).val();
		var brandId = $("#brandId"+list[i]).val();
		if(brandIds == brandId){
			var option=new Option(brandCname, brandId)
			option.selected=true;
			obj.options.add(option);
		}else{
			obj.options.add(new Option(brandCname, brandId));
		}
	}
	if(operate=='edit'){
		chenageDeductCode(null,'${base.isGuarantee}');
	}
});

function chenageDeductCode(t,value){
	if(value ==="0" ||value ===""){
		$("#guaranteeType").attr("disabled","disabled");
		$("#isCommGuarantee").attr("disabled","disabled");
		$("#guaranteeAmount").attr("disabled","disabled");
		$("#countbase_base").attr("disabled","disabled");
		$("#isCommGuarantee").children("option").each(function(){
			if($(this).val() == ""){
				$(this).attr("selected","selected");
			}
		});
		$("#countbase_base").children("option").each(function(){
			if($(this).val() == ""){
				$(this).attr("selected","selected");
			}
		});
	}else if(value ==="1"){
		$("#guaranteeType").removeAttr("disabled");
		$("#isCommGuarantee").removeAttr("disabled");
		$("#guaranteeAmount").removeAttr("disabled");
		$("#countbase_base").removeAttr("disabled");
		if('${base.isCommGuarantee}'==null||'${base.isCommGuarantee}'==""){
			$("#isCommGuarantee").children("option").each(function(){
				
				if($(this).val() == "0"){
					$(this).attr("selected","selected");
				}
			});
		}
		if('${base.countBase}'==null||'${base.countBase}'==""){
			$("#countbase_base").children("option").each(function(){
				if($(this).val() == "0"){
					$(this).attr("selected","selected");
				}
			});
		}
	}
}

</script>
</head>
<body>
<div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                 <h4 class="modal-title">销售分成及结算</h4>
            </div>			<!-- /modal-header -->
            <div class="modal-body">
            <table class="table">  
            	<tr>
            	
				</tr>
					<tr>
	            	<%-- 	<td   >
	  	 					<div class="col-sm-12">
								    <label for="isCompare_lab" class="col-sm-5 control-label">是否比高:</label>
									<div class="  col-sm-7">
											<ossp:select id="isCompare" defaultSelected="${base.isCompare}" class_="form-control" dictType="COMPARE_HIGH"></ossp:select>
									</div>
							  	</div>
						</td> --%>
							<td  >
  	 					<div class="col-sm-12">
							    <label for="brand" class="col-sm-5 control-label">品牌:</label>
									<div class=" input-group col-sm-7">
									<select id="brandName" class="form-control" ></select>
										<input type="hidden" id="barndId_base"  value="${base.brandsId}">
										<input type="hidden"  id="operate_base" value="${operate}"/>
										<input type="hidden"  id="base_seq" value="${num}"/>
								</div>
						  	</div>
					</td>
							<td>
  	 					<div>
							<label for="isGuarantee_lab" class="col-sm-5 control-label">是否保底:</label>
								<div class=" col-sm-7">
										<ossp:select id="isGuarantee" onchange="chenageDeductCode(this,this.options[this.options.selectedIndex].value)"  defaultSelected="${base.isGuarantee}" class_="form-control" dictType="DEFEND_BASE"></ossp:select>
								</div>
						  	</div>
					</td>
					
				 </tr>
				<tr>
					<td  >
  	 					<div>
							    <label for="guaranteeType_lab" class="col-sm-5 control-label">保底形式:</label>
								<div class=" col-sm-7">
										<ossp:select id="guaranteeType" disabled="disabled" defaultSelected="${base.guaranteeType}" class_="form-control" dictType="GUARANTEE_TYPE"></ossp:select>
								</div>
						  	</div>
					</td>
					<td  >
  	 						<div class="col-sm-12">
							    <label for="amount_lab" class="col-sm-5 control-label">保底金额:</label>
								<div class=" col-sm-7">
										<input type="text" value="${base.guaranteeAmount}" disabled="disabled" id="guaranteeAmount" class="form-control">
										
								</div>
						  	</div>
					</td>
				</tr>
				
				<tr>
            
					<td  >
  	 					<div class="col-sm-12">
							    <label for="codeType_lab" class="col-sm-5 control-label">销售码类型:</label>
								<div class=" col-sm-7">
								
										<ossp:select  defaultSelected="${base.codeType}" class_="form-control" id="codeType"  dictType="CONTRACT_CODE_TYPE"></ossp:select>
								</div>
						</div>
				
					</td>
							<td  >
	  	 					<div class="col-sm-12">
								    <label for="deductType_lab" class="col-sm-5 control-label">扣款方式:</label>
									<div class="  col-sm-7">
											<ossp:select defaultSelected="${base.deductType}" dictType="PAYMENT_TYPE" id="deductType_base" class_="form-control"></ossp:select>
									</div>
							  	</div>
						</td>
				</tr>
				
		
				
				<tr>
					<td>
						<div class="col-sm-12">
							    <label for="upper_lab" class="col-sm-5 control-label">扣款下限:</label>
								<div class=" col-sm-7">
										<input  id="lower" value="${base.lower}" class="form-control"/>		
								</div>
						</div>
						
						</td>
	            		<td  >
	  	 					<div class="col-sm-12">
								    <label for="lower_lab" class="col-sm-5 control-label">扣款上限:</label>
									<div class="  col-sm-7 ">
											<input  id="upper" value="${base.upper}" path="" class="form-control"/>
									</div>
							  	</div>
						</td>
					
				 </tr>
				 <tr>
	            		<td  >
	  	 					<div class="col-sm-12">
								    <label for="tstartDate_lab" class="col-sm-5 control-label">开始日期:</label>
									<div class="  col-sm-7">
									 		<div class="input-group date startDate " data-date="" data-date-format="yyyy-mm-dd" >
										          <input class="form-control" value="<fmt:formatDate value="${base.startDate}" type="both" pattern="yyyy-MM-dd"/>" id="startDate_base" name="startDate_base" disabled="disabled"    size="10"  data-rule="required" type="text" />
							                   	 <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
						                	</div>
									</div>
							  	</div>
						</td>
						
						<td  >
	  	 					<div class="col-sm-12">
								    <label for="endDate_lab" class="col-sm-5 control-label">结束日期:</label>
									<div class="  col-sm-7">
										<div class="input-group date startDate " data-date="" data-date-format="yyyy-mm-dd" >
										          <input class="form-control" id="endDate_base" name="endDate_base" disabled="disabled"   value="<fmt:formatDate value="${base.endDate}" type="both" pattern="yyyy-MM-dd"/>"    size="10"  data-rule="required" type="text" />
							                    <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
						                	</div>
									</div>
							  	</div>
						</td>
				 </tr>
				 <tr>
	            		<td  >
	  	 					<div class="col-sm-12">
								    <label for="validType_lab" class="col-sm-5 control-label">时效类型:</label>
									<div class="  col-sm-7">
											<ossp:select class_="form-control" id="validType_base"  defaultSelected="${base.validType}"  dictType="DEFEND_SYTLE"></ossp:select>	
											
									</div>
							  	</div>
						</td>
						
		
							<td  >
							<input type="hidden" class="form-control" id="countBase_Name" placeholder="请选择商品分类" readonly="readonly" class="form-control required">
	  	 					<div class="col-sm-12">
								    <label for="taxRate_lab" class="col-sm-5 control-label">扣率:</label>
									<div class="  col-sm-7">
											<input  id="deductRate"  class="form-control" value="${base.deductRate}"/>
									</div>
							  	</div>
							  <input type="hidden" id="payDate_base" >
							<%-- <ossp:select  id="payDate"  dictType="PAY_DATE" class_="form-control" defaultSelected="${base.payDate}"></ossp:select> --%>	
						</td>
					 </tr>
		
				 	 <tr>
	            	
						<td  >
	  	 					<div class="col-sm-12">
								    <label for="isCommGuarantee_lab" class="col-sm-5 control-label">通用保底:</label>
									<div class="  col-sm-7">
										<ossp:select style=" hidden"  id="isCommGuarantee" disabled="disabled" dictType="ISCOMM_GUARANTEE" class_="form-control" defaultSelected="${base.isCommGuarantee}"></ossp:select>		
									</div>
							 </div>
						</td>
						<td>
	  	 				   <div class="col-sm-12">
								    <label for="countbase_base_lab" class="col-sm-5 control-label">促销是否计入保底:</label>
									<div class="  col-sm-7">
										<ossp:select  id="countbase_base" disabled="disabled" dictType="COUNTBASE_BASE" class_="form-control" defaultSelected="${base.countBase}"></ossp:select>
									</div>
							 </div>
						</td>
				 </tr> 	 	 		
				 <tr>
	            		<td   colspan="2">
	  	 							<div class="col-sm-12">
								    <label for="remarks_lab"  class="col-sm-2 control-label">备注  :</label>
									<div class=" col-sm-7">
									<textarea  id="remarks_base"      class="form-control">
										${base.remarks}
									</textarea>
									
								
									</div>
							  	</div>
						</td>
						
				 </tr> 
			</table>
				
            </div>			
            <!-- /modal-body -->
            <div class="modal-footer">
               <!--  <button type="button" id="ok" onclick="btnBaseOk_click()"  class="btn btn-primary" onclick="">确定</button> -->
                 <button type="button"  class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>			
            <!-- /modal-footer -->
        </div>         
        <!-- /modal-content -->
    </div>     
   <script type="text/javascript">
	$('.startDate').datetimepicker({
        language:  'zh-CN',
        weekStart: 1,
        todayBtn:  1,
		autoclose: 1,
		todayHighlight: 1,
		startView: 2,
		minView: 2,
		forceParse: 0,
		setLocalDate: new Date(2011, 2, 5),
		format: 'yyyy-mm-dd'
    })

	$('.endDate').datetimepicker({
        language:  'zh-CN',
        weekStart: 1,
        todayBtn:  1,
		autoclose: 1,
		todayHighlight: 1,
		startView: 2,
		minView: 2,
		forceParse: 0,
		format: 'yyyy-mm-dd'	
    })


</script>
</body>
